<?php

namespace App\Admin\Controllers;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use \App\Models\CouponRecord;
use \App\Models\Coupon;

class CouponRecordsController extends AdminController
{
    protected $title = '卡卷记录';
    
    protected function grid()
    {
        $grid = new Grid(new CouponRecord());

	    $grid->disableExport();
	
	    $grid->column('id', 'ID');
	    $grid->column('user_id', '会员')->display(function () {
	        return $this->user ? $this->user->nameText(true) : '';
        });
	    $grid->column('coupon_id', '卡卷')->display(function ($value) {
		    return $this->coupon ? $this->coupon->name : '';
	    });
	    $grid->column('code', '核销码');

	    $grid->column('status', '卡卷状态')->display(function ($value) {
		    return  !empty($value) ? config('site.couponStatus')[$value] : '';
	    });
	   
	    $grid->column('used_at', '使用时间')->display(function ($value) {
		      return $this->used_at;
	    });

	    $grid->column('expired_at', '过期时间')->display(function ($value) {
		      return $this->expired_at;
	    });
	    
	    $grid->column('created_at', '创建时间')->display(function () {
		    return $this->created_at->toDatetimeString();
	    });
	
	    $grid->disableRowSelector();

        return $grid;
    }
	
	 protected function detail($id)
    {
        $show = new Show(CouponRecord::findOrFail($id));
        return $show;
    }
	
    
}
